
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        人员添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <link rel="icon" th:href="@{/images/favicon.ico}" type="image/x-icon"/>
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"></script>
    <link rel="stylesheet" th:href="@{/css/index.css}">
    <style>
        .imgs{display: none;}
        .picture{display: none;}
    </style>

</head>
<body>
<div id="app">
    <div class="x-nav" style="margin-left: 20%">
        <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>业主信息管理</cite></a>
              <a><cite>{{title}}</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>

    <div class="x-body" style="margin-left: 20%">
    <el-form :model="owner" :rules="rules" ref="ownerFormRef" label-width="120px" class="demo-ruleForm">
        <el-form-item label="小区名称" prop="communityName">
            <el-select v-model="owner.communityName" placeholder="请选择" @change="selectChange">
                <el-option
                        v-for="item in communityList"
                        :value="item.communityName">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="成员名称" prop="ownerName">
            <el-input v-model="owner.ownerName"></el-input>
        </el-form-item>

        <el-form-item label="身份证号" prop="idcard">
            <el-input v-model="owner.idcard"></el-input>
        </el-form-item>
        <el-form-item label="联系方式" prop="telephone">
            <el-input v-model="owner.telephone"></el-input>
        </el-form-item>
        <el-form-item label="职业" prop="profession">
            <el-input v-model="owner.profession"></el-input>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
            <el-input v-model="owner.birthday"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
            <el-input v-model="owner.remark"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
            <el-radio-group v-model="owner.sex">
                <el-radio label="0">男</el-radio>
                <el-radio label="1">女</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="成员类型" prop="type">
            <el-radio-group v-model="owner.type">
                <el-radio label="0">房主</el-radio>
                <el-radio label="1">租客</el-radio>
            </el-radio-group>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="save()" style="text-align: center">保存</el-button>
            <el-button @click="clearAll()" style="text-align: center">重置</el-button>
        </el-form-item>
    </el-form>
    </div>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/x-layui.js}" charset="utf-8"></script>
<!--导入Vue依赖包-->
<script th:src="@{/js/vue.js}" charset="utf-8"></script>
<!-- 引入Element组件库 -->
<script th:src="@{/js/index.js}"></script>
<!--导入Axios依赖包-->
<script th:src="@{/js/axios.js}" charset="utf-8"></script>
<script type="text/javascript">
    window.onload = function () { //页面加载完成后再执行
        axios.post("/community/find", this.searchMap).then((res) => {
            console.log(res)
            app.communityList = res.data.data;
        });
    };
    var app = new Vue({
        el: "#app",
        data: {
            title: "添加小区",
            owner: {ownerPicture: "", ownerId: ""},
            communityList:[],
            fileList: [],
            rules: {
                communityName: [
                    {required: true, message: '请输入小区名称', trigger: 'blur'},
                    {max: 50, message: '长度小于50个字符', trigger: 'blur'}
                ],
                houseName: [
                    {required: true, message: '请输入房产名称', trigger: 'blur'},
                    {min: 3, max: 20, message: '长度必须大于11、小于20个字符', trigger: 'blur'}
                ],
                ownerName: [
                    {required: true, message: '请输入姓名', trigger: 'blur'}
                ],
                idcard: [
                    {required: true, message: '请输入身份证号码', trigger: 'blur'}
                ],
                telephone: [
                    {required: true, message: '请输入电话号码', trigger: 'blur'}
                ],
                profession: [
                    {required: true, message: '请输入职业', trigger: 'blur'}
                ],
                birthday: [
                    {required: true, message: '请输入生日', trigger: 'blur'},
                ],
                remark: [
                    {required: true, message: '请输入备注', trigger: 'blur'}
                ],
                sex: [
                    {required: true, message: '请选择性别', trigger: 'change'}
                ],
                type: [
                    {required: true, message: '请选择成员类型', trigger: 'change'}
                ]
            }
        },
        methods: {
            findById() {
                axios.get("/owner/findById?ownerId=" + this.owner.ownerId).then((res) => {
                    this.owner = res.data.data;

                });
            },
            selectChange(){
                axios.post("/community/find", this.searchMap).then((res) => {
                    console.log(res)
                    app.communityList = res.data.data;
                });
            },
            //表达重置
            clearAll() {
                this.$refs.ownerFormRef.resetFields();
                if (this.fileList.length > 0) {
                    this.handleRemove();
                }
            },
            save() {
                var method = "";
                console.log(this.owner.ownerId)
                if (this.owner.ownerId != null) {
                    method = "update"
                } else {
                    method = "add"
                }
                axios.post("/owner/" + method, this.owner).then((res) => {
                    console.log(method)
                    if (res.data.flag) {
                        this.$message({
                            message: res.data.message,
                            type: 'success'

                        });

                    }

                });
                this.findById();
            },

            getQueryString(name) {
                let reg = `(^|&)${name}=([^&]*)(&|$)`
                let r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
        },
        created: function () {
            layui.use(['element', 'layer', 'form'], function () {
                $ = layui.jquery;//jquery
                lement = layui.element();//面包导航
                layer = layui.layer;//弹出层
                form = layui.form();
                okLoading.close($);
            });
            //获取父页面传递参数，小区ID
            this.owner.ownerId = this.getQueryString("ownerId");
            //根据小区ID获取小区对象，进行数据回显
            if (this.owner.ownerId != null && this.owner.ownerId != '') {
                this.title = "修改小区";
                this.selectChange();
                this.findById();
            }

        }
    });
</script>


</body>
</html>